import java.util.*;

/**
 * 子串分值
 * 动态规划超时
 */
public class SubstringScore {
    static Map<String, Integer> mapAll = new HashMap<>();
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        String str = scan.nextLine();
        int len = str.length();
        int sum = 0;
        char[] arr = str.toCharArray();
        dfs(arr, len);
        for (Map.Entry entry : mapAll.entrySet()) {
            sum += (int) entry.getValue() * getPartSum((String) entry.getKey());
        }
        System.out.println(sum);
        scan.close();
    }

    public static void dfs(char[] arr, int len) {
        for (int i = 0; i < len; i++) {
            StringBuilder str = new StringBuilder(Character.toString(arr[i]));
            mapAll.put(str.toString(), mapAll.getOrDefault(str.toString(), 0) + 1);
            for (int j = i + 1; j < len; j++) {
                str.append(arr[j]);
                mapAll.put(str.toString(), mapAll.getOrDefault(str.toString(), 0) + 1);
            }
        }
    }


    public static int getPartSum(String str) {
        int len = str.length();
        if (len == 1) {
            return 1;
        }
        char[] arr = str.toCharArray();
        int[] dp = new int[len];
        dp[0] = 1;
        Set<Character> set = new HashSet<>();
        set.add(arr[0]);
        Map<Character, Integer> map = new HashMap<>();
        map.put(arr[0], 1);
        for (int i = 1; i < len; i++) {
            if (set.add(arr[i])) {
                dp[i] = dp[i - 1] + 1;
                map.put(arr[i], 1);
            } else {
                if (map.get(arr[i]) == 1) {
                    dp[i] = dp[i - 1] - 1;
                } else {
                    // 说明前面已经减过了
                    dp[i] = dp[i - 1];
                }
                map.replace(arr[i], map.get(arr[i]) + 1);
            }
        }
        return dp[len - 1];
    }
}
